/**
 * Created by IAN on 2016/10/14.
 */
var filed8 = getQueryString("filed8");
$(function () {
    var sel = $.Params.create();
    sel.addParams("page",0);
    sel.addParams("rows",rows);
    getData();

    //查询
    $("#searchBtn").on("click",function(){
        var pTitle = $("#pTitle").val().trim();
        var cTitle = $("#cTitle").val();
        var hospitalName = $("#hospitalName").val();
        var hospitalOffices = $("#hospitalOffices").val();
        if(pTitle!=""){
            sel.addParams("pTitle",pTitle);
        }else{
            sel.addParams("pTitle",undefined);
        }
        if(cTitle!=""){
            sel.addParams("cTitle",cTitle);
        }else{
            sel.addParams("cTitle",undefined);
        }
        if(hospitalName!=""){
            sel.addParams("hospitalName",hospitalName);
        }else{
            sel.addParams("hospitalName",undefined);
        }
        if(hospitalOffices!="0"){
            sel.addParams("hospitalOffices",hospitalOffices);
        }else{
            sel.addParams("hospitalOffices",undefined);
        }
        getData();
    })


    //批量解绑
    $('#unBind').on("click",function(){
        var params = getCheckData();
        if(params != "") {
            if(confirm("确定要解除绑定吗！")){
                var unbindSel = $.Params.create();
                unbindSel.addParams("params", params);
                unbindSel.addParams("filed8","");
                unbindSel.ajax(getIP() + "member/unBindRespresent", function (data) {
                    if (data.success) {
                        alert(data.msg);
                        getData();
                    }
                })
            }
        }else{
            alert("请至少选中一项");
        }
    });


    //判断checkbox状态
    $("#selAll").on("click",function () {
        if(!$(this).attr("checked")){
            $("input[type=checkbox]").attr("checked","checked")
        }else{
            $("input[type=checkbox]").removeAttr("checked");
        }
    })


    //获取数据
    function getData(){
        sel.addParams("filed8",filed8);
        getPageData(sel,getIP()+"member/getMemberPages",function(data){
            if(data.success){
                var html = "";
                if(data.total > 0){
                    $.each(data.result, function(i,val) {
                        var sex = val.sex;
                        if(val.sex == 1){
                            sex="男";
                        }else if(val.sex == 2){
                            sex="女";
                        }else{
                            sex="";
                        }
                        if(val.email == null){
                            val.email = "";
                        }
                        if(val.filed10 == null){
                            val.filed10 = "0";
                        }

                        html+="<tr role='row'' class='even'>" +
                            "<td><input eid='"+val.id+"' onclick='getCheck(this)' type='checkbox' class='classOption'></td>" +
                            "<td class='sorting_1'>"+val.name+"</td>" +
                            "<td>"+val.tel+"</td>"+
                            "<td>"+val.email+"</td>"+
                            "<td>"+sex+"</td>"+
                            "<td>"+val.hospitalName+"</td>"+
                            "<td>"+val.hospitalOffices+"</td>"+
                            "<td>"+val.filed10+"</td>"+
                            "<td>"+val.createTime+"</td>"+
                            "<td><button type='button' class='btn btn-primary'  onclick='unbind(\""+val.id+"\")'>解绑</button></td>" +
                            "</tr>";
                    });
                }else{
                    html="<tr role='row' class='even'><td colspan='10' class='txCenter'>暂无数据</td></tr>";
                }

                $("#listContainer").html(html);
            }
        })
    }

});

function unbind(memberId){
    var memBindSel = $.Params.create();
    memBindSel.addParams("id",memberId);
    memBindSel.addParams("filed8","");
    memBindSel.ajax(getIP()+"member/updmember",function(data){
        if(data.success){
            alert("解绑成功！");
            window.location.href = "memberDoctorList.html?filed8="+filed8;
        }
    })
}


